<?php
class ThumbnailUtility
{
    public static function addByPhoto(PhotoModel $photo)
    {
        $sizes = ThumbnailModel::model()->findAll();
        foreach($sizes as $size)
        {
            self::resize($photo->filename, $size->width, $size->height);
        }
    }
    
    private static function resize($filename, $width, $height)
    {
        $photoPath = PhotoUtility::getPath();
        $thumbnailPath = self::getPath($width, $height);
        $image = Yii::app()->thumbnail->create($photoPath.'/'.$filename);
        $image->resize($width, $height);
        $image->save($thumbnailPath.'/'.$filename);
    }
    
    public static function getPath($width, $height)
    {
        return Yii::app()->params[ENUM_CONFIG_PARAM_PHOTO_PATH].'/'.$width.'x'.$height;
    }

    public static function getUrl($width, $height)
    {
        return Yii::app()->params[ENUM_CONFIG_PARAM_PHOTO_URL].'/'.$width.'x'.$height;
    }
}